<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        #app {
            width: 500px;
            height: 100%;
            margin: auto;
        }

        .title {
            font-size: 20px;
            height: 30px;
            line-height: 30px;
            font-weight: bold;
        }

        .inbox {
            width: 100%;
            height: 40px;
        }

        input {
            display: inline-block;
            width: 300px;
            height: 30px;
            padding-left: 10px;
            box-sizing: border-box;
            margin-top: 10px;
            outline: none;
            /* border: none; */
            border-radius: 5px;
            background-color: palevioletred;
            border: 1px solid plum;
        }

        button {
            display: inline-block;
            width: 50px;
            height: 30px;
            background-color: paleturquoise;
            border: none;
            border-radius: 5px;
        }

        .list {
            height: 200px;
            width: 100%;
        }

        h2 {
            display: inline-block;

        }

        span {
            margin-left: 200px;
        }

        .hist {
            display: block;
            height: 30px;
            width: auto;
            /* border: 1px solid palegoldenrod; */
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="title">搜索</div>
        <div class="inbox">
            <input type="text" placeholder="请输入" v-model="inputText">
            <button @click="add()">搜索</button>
        </div>
        <div class="list">
            <h2>历史搜索</h2><span @click="clear()">清空</span>
            <div class="hist" v-for="(item,index) in tasklist">{{item.name}}</div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',
            tasklist: [],
        },
        methods: {
            add() {
                if (this.inputText) {
                    var obj = { name: this.inputText }
                    this.tasklist.push(obj)
                    this.inputText = ''
                }
            },
            clear() {
                this.tasklist = []
            }
        }
    })
</script>